#pragma once

#include <QWidget>
#include <qbmessage/include/message_kernel.h>

class MainFrame;
class SImageButton;
class AppMenu;
class TabBar;
class QPropertyAnimation;
class KeySearchWidget;
class StatusBar;

class TitleBar
	: public QWidget
	, public CUnknownObject<IMessageKernelObserver>
{
	Q_OBJECT
	Q_PROPERTY(int animateProgess READ progress WRITE setProgress)
public:
	TitleBar(MainFrame* frame, QWidget* parent = nullptr);
	~TitleBar();

	void maximizeMainFrame(bool max);
	KeySearchWidget* searchWidget() const { return m_searchWidget; }
	void showSearch();

public slots:
	void onCommonPage(int* ids, int size, int ntype);

protected slots:
	void onBtnClicked();
	void onTabNeedResize(int type);
	void onSearchResultHide();
	void onAnimationFinished();
signals:
	void setConfigAuth(int* ids, int size);
	void setCommonPage(int* ids, int size, int ntype);
protected:
	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;
	void mouseDoubleClickEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void resizeEvent(QResizeEvent* event) override;

	STDMETHOD_(void, OnRecvMsg) (char* pData, int nDataLen) {}
	STDMETHOD_(void, OnRecvNetStatus) (qb::NetStatus status, short retcode);

private:
	int progress() const { return m_animateProgess; }
	void setProgress(int p);
	void startResizeAnimation(bool showSearch);

private:
	MainFrame* m_frame = nullptr;
	AppMenu* m_menu = nullptr;
	KeySearchWidget* m_searchWidget = nullptr;
	TabBar* m_tabBar = nullptr;
	SImageButton* m_btnSearch = nullptr;
	QPoint		m_lastMPos;
	bool		m_canDrag = false;
	bool		m_searchWidgetHide = false;
	QPropertyAnimation* m_animation = nullptr;
	int			m_animateProgess = 0;
	SImageButton* m_btnMin = nullptr;
	SImageButton* m_btnFull = nullptr;
	SImageButton* m_btnClose = nullptr;
	SImageButton* m_btnRestore = nullptr;
	StatusBar* m_statusBar = nullptr;
	QRect m_rcLogin;
	QString m_strStatus;
};